/**
 * Version 14 mrt 2008 - initial version
 */
package audioreaper.tools;


/**
 * <code>WaveFormGenerator</code>.
 *
 * @author <a href="mailto:vincent@nazarene.nl">Vincent van Beveren</a>
 *
 */
public class WaveFormGenerator {

	private final WaveForm _prototype;
	private final int _sampleRate;
	private float _currentPos;
	private float _frequency;
	
	private float _stepSize;
	
	
	public WaveFormGenerator(WaveForm prototype, int sampleRate, float initialFrequency) {
		_prototype = prototype;
		_sampleRate = sampleRate;
		_frequency = initialFrequency;
		calcValues();
	}
	
	
	private void calcValues() {
		_stepSize = ((float)_prototype.getLength() * _frequency) / _sampleRate;
	}


	public int getNextSample() {
		return _prototype.getSample(nextPos());
	}

	/**
	 * 
	 */
	private int nextPos() {
		_currentPos = (_currentPos + _stepSize) % _prototype.getLength(); 
		return (int)_currentPos;
	}
	
	
	
	
}
